package com.hymjweb.demo.hymj.native_bill_manage.pull_cost.service;

import com.hymjweb.demo.framework.sys.BaseService;
import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.hymj.native_bill_manage.pull_cost.bean.BNativeBillPullCostPojo;
import com.hymjweb.demo.hymj.native_bill_manage.pull_cost.mapper.BNativeBillPullCostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BNativeBillPullCostService extends BaseService {

    @Autowired
    private BNativeBillPullCostMapper bNativeBillPullCostMapper;

    public List<BNativeBillPullCostPojo> queryListByMasterBillId(String masterBillId) throws Exception {
        if(DataTypeUtil.isEmptyStr(masterBillId)){
            throwException("检索分单全拉货成本表参数错误!");
        }
        return bNativeBillPullCostMapper.queryListByMasterBillId(masterBillId);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int insert(BNativeBillPullCostPojo bNativeBillPullCostPojo) throws Exception {
        if(bNativeBillPullCostPojo == null){
            throwException("主单全拉分摊成本参数错误!");
        }
        return bNativeBillPullCostMapper.insert(bNativeBillPullCostPojo);
    }


    @Transactional(rollbackFor = {Exception.class})
    public int update(BNativeBillPullCostPojo bNativeBillPullCostPojo) throws Exception {
        if(bNativeBillPullCostPojo == null){
            throwException("主单全拉分摊成本参数错误!");
        }
        return bNativeBillPullCostMapper.update(bNativeBillPullCostPojo);
    }

    @Transactional(rollbackFor = {Exception.class})
    public int deleteByMasterBillId(String masterBillId) throws Exception {
        if(DataTypeUtil.isEmptyStr(masterBillId)){
            throwException("主单全拉分摊成本删除参数错误!");
        }
        return bNativeBillPullCostMapper.deleteByMasterBillId(masterBillId);
    }
}
